package com.imooc.activitiweb.mapper;

import com.imooc.activitiweb.pojo.JmEnclosure;
import com.imooc.activitiweb.pojo.Project;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
@Component
public interface ProMapper {

    //获取项目集合
    List<Project> selectJmPro(HashMap hashMap);

    Project selectJmProById(HashMap hashMap);

    int batchSavePro(List<Project> projectList);

    int insertJmEnclosure(JmEnclosure jmEnclosure);

    JmEnclosure queryFileById(@Param("fileId") String fileId);

    @Delete("delete from jm_enclosure where id=#{fileId}")
    int deleteFileById(@Param("fileId") String fileId);

    @Select("select * from jm_declare where PROC_INST_ID_=#{processInstanceId}")
    Map queryJmDeclareByProcessInstanceId(@Param("processInstanceId") String processInstanceId);

    List<JmEnclosure> queryJmEnclosureByProcessInstanceIdAndFormKey(@Param("processInstanceId") String processInstanceId,
                                                                               @Param("formKey") String formKey);
    @Select("select id,name from jm_node where name=#{name}")
    HashMap<String,Object> queryPageIndexByTaskName(@Param("name") String name);

    int insertJmDeclare(Map map);

    int editJmDeclare(Map map);

    int batchSaveProRes(List<Project> projectList);

    List<Project> selectJmProRes(@Param("processInstanceId") String processInstanceId);

    List<Map> getDeclareList(HashMap hashMap);

    @Delete("DELETE FROM jm_pro_res where PROC_INST_ID_=#{instanceID};" +
            "DELETE FROM jm_enclosure where PROC_INST_ID_=#{instanceID};" +
            "DELETE FROM jm_declare where PROC_INST_ID_=#{instanceID}")
    int deleteDeclareAndEnclosureAndProResByProcessInstanceId(@Param("instanceID") String instanceID);

    int savePro(Project project);

    @Delete("DELETE FROM jm_pro where id=#{id}")
    int delPro(@Param("id") String id);

    int updatePro(Project project);

    @Select("select name from user where username=#{username}")
    String queryNameByUsername(@Param("username") String username);
}
